package org.opens.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.opens.dao.EmpDao;
import org.opens.entity.Emp;
import org.opens.entity.PagerParam;
import org.opens.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Date 2021/5/23 14:25
 * @Created by 99126
 */
@Service(value = "empService")
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpDao empDao;

    @Override
    public IPage<Emp> page(PagerParam pagerParam) {
        if (pagerParam.getPageSize() == null || pagerParam.getPageNumber() == null) {
            throw new RuntimeException("分页参数异常, 无法分页");
        }
        Page<Emp> page = new Page<>(pagerParam.getPageNumber(), pagerParam.getPageSize());
        if (StrUtil.isNotEmpty(pagerParam.getEname())) {
            pagerParam.setEname("%" + pagerParam.getEname() + "%");
        }
        return empDao.page(page, pagerParam);
    }
}
